﻿// JavaScript Document
var SB_style = {
	table:"selectBarTable",
	selectbar:"Main_selectBar",
	selectbar_head:"Main_selectBar_head",
	selectbar_body:"Main_selectBar_body",
	selectbar_foot:"Main_selectBar_foot",
	seekblock:"seekblock",
	input_seek:"input_seek",
	icon_close:"close",
	icon_seek:"seek",
	selectbox:"selectbox",
	slc_sort:"slc_sort",
	normal:"normal",
	active:"active",
	arrow_left:"arrow_left",
	arrow_right:"arrow_right",
	arrow_all_left:"arrow_all_left",
	arrow_all_right:"arrow_all_right"
}
CommonFunctions._isIE6 = window.navigator.appVersion.indexOf("MSIE 6") != -1;
function SelectBlock(arr_left,arr_right,arr_sbj,styles,multiple){
	try{
		this.arr_left = arr_left;
		this.arr_right = arr_right;
		this.arr_sbj = arr_sbj;
		this.styles = styles;
		this.multiple = multiple;
		
		var oTable;
		var oTd_leftSelectBlock;
		var oTd_arrowsBlock;
		var oTd_rightSelectBlock;
		
		this.createToObj = function(obj){
			var oTr;
			var oTbody;
			oTable = document.createElement('table');
			oTable.cellPadding = 0;
			oTable.cellSpacing = 0;
			oTable.border = 0;
			oTable.className = this.styles.table;
			oTr = document.createElement('tr');
			oTd_leftSelectBlock = document.createElement('td');
			oTd_arrowsBlock = document.createElement('td');
			oTd_rightSelectBlock = document.createElement('td');
			createSelectBlock(this.styles,this.arr_left,this.arr_sbj,oTd_leftSelectBlock);
			createSelectBlock(this.styles,this.arr_right,this.arr_sbj,oTd_rightSelectBlock);
			createArrowsBlock(this.styles,oTd_arrowsBlock);
			oTr.appendChild(oTd_leftSelectBlock);
			oTr.appendChild(oTd_arrowsBlock);
			oTr.appendChild(oTd_rightSelectBlock);
			if(CommonFunctions._isIE){
				oTbody = document.createElement('tbody');
				oTbody.appendChild(oTr);
				oTable.appendChild(oTbody);
			}else{
				oTable.appendChild(oTr);
			}
			obj.appendChild(oTable);
		}
		function createSelectBlock(styles,arr,sbj,obj){
			var oSelectBlock;
			var oSelectBlock_head;
			var oSelectBlock_body;
			var oSelectBlock_foot;
			var oSeekblock;
			var oInput_seek;
			var oA_handle;
			var oSelectbox;
			var oSelectbox_slc;
			var oSelectbox_opt;
			var oSelectbox_txt;
			var oSelectbox_ul = [];
			var oSelectbox_li;
			var oSelectbox_a;
			var count = 0;
			var l_i,r_i;
			
			oSelectBlock = document.createElement('div');
			oSelectBlock.className = styles.selectbar;
			oSelectBlock_head = document.createElement('div');
			oSelectBlock_head.className = styles.selectbar_head;
			oSelectbox_slc = document.createElement('select');
			oSelectbox_slc.className = styles.slc_sort;
			oSelectbox_slc.onchange = function(){
				for(var i = 0; i < oSelectbox_ul.length; i++){
					oSelectbox_ul[i].style.display = "none";
				}
				oSelectbox_ul[this.value].style.display = "";
			}
			var hasContent = true;
			for(var i = 0; i < arr.length; i++){
				if(arr[i][0].subject != null){
					oSelectbox_opt = document.createElement('option');
					oSelectbox_opt.innerHTML = arr[i][0].subject;
					oSelectbox_opt.value = i;
					oSelectbox_slc.appendChild(oSelectbox_opt);
					
					hasContent = true;
				}else{
					hasContent = false;
				}
			}
			
			if(hasContent == false){
				//oSelectBlock_head.innerHTML = "<br/>";
			}else{
				oSelectbox_txt = document.createTextNode(sbj.service_title);
				oSelectBlock_head.appendChild(oSelectbox_txt);
				oSelectBlock_head.appendChild(oSelectbox_slc);
				//oSelectBlock_head.innerHTML = oSelectbox_slc.outerHTML + "<br/>";
			}
			var oBr = document.createElement('br');
			oSelectBlock_head.appendChild(oBr);
			oSelectbox_txt = document.createTextNode(obj == oTd_leftSelectBlock ? sbj.subject_left : sbj.subject_right);
			oSelectBlock_head.appendChild(oSelectbox_txt);
			
			oSelectBlock_body = document.createElement('div');
			oSelectBlock_body.className = styles.selectbar_body;
			oSelectBlock_foot = document.createElement('div');
			oSelectBlock_foot.className = styles.selectbar_foot;
			
			oSeekblock = document.createElement('div');
			oSeekblock.className = styles.seekblock;
			oInput_seek = document.createElement('input');
			oInput_seek.type = "text";
			oInput_seek.className = styles.input_seek;
			oInput_seek.onkeyup = function(){
				oSeekblock.style.top = 0;
				var c = hasContent == false ? 0 : oSelectbox_slc.value;
				for(var i = 0; i < oSelectbox_ul[c].getElementsByTagName('li').length; i++){
					oSelectbox_ul[c].getElementsByTagName('li')[i].style.display = "";
					oSelectbox_ul[c].getElementsByTagName('li')[i].getElementsByTagName('a')[0].className = styles.normal;
				}
				if(this.value != ""){
					for(var i = 0; i < oSelectbox_ul[c].getElementsByTagName('a').length; i++){
						if(oSelectbox_ul[c].getElementsByTagName('a')[i].innerHTML.toLowerCase().indexOf(this.value.toLowerCase()) == -1){
							
							oSelectbox_ul[c].getElementsByTagName('a')[i].parentNode.style.display = "none";
						}
					}
					oA_handle.className = styles.icon_close;
					oA_handle.href = "javascript:void(0)";
					oA_handle.onclick = function(){
						oInput_seek.value = "";
						oInput_seek.focus();
						this.className = styles.icon_seek;
						this.removeAttribute("href");
						for(var i = 0; i < oSelectbox_ul[c].getElementsByTagName('li').length; i++){
							oSelectbox_ul[c].getElementsByTagName('li')[i].style.display = "";
						}
					}
				}else{
					oA_handle.className = styles.icon_seek;
					oA_handle.removeAttribute("href");
					for(var i = 0; i < oSelectbox_ul[c].getElementsByTagName('li').length; i++){
						oSelectbox_ul[c].getElementsByTagName('li')[i].style.display = "";
					}
				}
			}
			oA_handle = document.createElement('a');
			oA_handle.className = styles.icon_seek;
			oA_handle.onfocus = function(){
				this.blur();
			}
			oSeekblock.appendChild(oInput_seek);
			oSeekblock.appendChild(oA_handle);
			oSelectBlock_body.appendChild(oSeekblock);
			oSelectbox = document.createElement('div');
			oSelectbox.className = styles.selectbox;
			for(var j = 0; j < arr.length; j++){
				oSelectbox_ul[j] = document.createElement('ul');
				oSelectbox_ul[j].id = arr[j][0].id;
				if(j == 0){
					oSelectbox_ul[j].style.display = "";
				}else{
					oSelectbox_ul[j].style.display = "none";
				}
				
				for(var i = 1; i < arr[j].length; i++){
					oSelectbox_li = document.createElement('li');
					oSelectbox_a = document.createElement('a');
					//oSelectbox_a.href = "javascript:void(0)";
					oSelectbox_a.className = styles.normal;
					oSelectbox_a.innerHTML = arr[j][i].name;
					oSelectbox_a.title = arr[j][i].title;
					oSelectbox_a.id = arr[j][i].id;
					if(multiple == false){
						oSelectbox_a.onclick = function(){
							oSeekblock.style.top = 0;
							if(this.className == styles.normal){
								var oAs = this.parentNode.parentNode.getElementsByTagName('a');
								for(var i = 0; i < oAs.length; i++){
									oAs[i].className = styles.normal;
								}
								this.className = styles.active;
								count = 1;
							}else{
								this.className = styles.normal;
								count = 0;
							}
						}
					}else{
						oSelectbox_a.onclick = function(){
							oSeekblock.style.top = 0;
							if(this.className == styles.normal){
								this.className = styles.active;
								count++;
							}else{
								this.className = styles.normal;
								count--;
							}
						}
					}
					oSelectbox_li.appendChild(oSelectbox_a);
					oSelectbox_ul[j].appendChild(oSelectbox_li);
					oSelectbox.appendChild(oSelectbox_ul[j]);
				}
				
				
				oSelectBlock_body.appendChild(oSelectbox);
			}
			
			
			oSelectBlock.appendChild(oSelectBlock_head);
			oSelectBlock.appendChild(oSelectBlock_body);
			oSelectBlock.appendChild(oSelectBlock_foot);
			
			obj.appendChild(oSelectBlock);
		}
		
		function createArrowsBlock(styles,obj){
			var oArrow_allright;
			var oArrow_right;
			var oArrow_allleft;
			var oArrow_left;
			
			oArrow_allright = document.createElement('a');
			oArrow_allright.className = styles.arrow_all_right;
			oArrow_allright.href = "javascript:void(0)";
			oArrow_allright.onfocus = function(){
				this.blur();
			}
			oArrow_right = document.createElement('a');
			oArrow_right.className = styles.arrow_right;
			oArrow_right.href = "javascript:void(0)";
			oArrow_right.onfocus = function(){
				this.blur();
			}
			oArrow_allleft = document.createElement('a');
			oArrow_allleft.className = styles.arrow_all_left;
			oArrow_allleft.href = "javascript:void(0)";
			oArrow_allleft.onfocus = function(){
				this.blur();
			}
			oArrow_left = document.createElement('a');
			oArrow_left.className = styles.arrow_left;
			oArrow_left.href = "javascript:void(0)";
			oArrow_left.onfocus = function(){
				this.blur();
			}
			
			oArrow_allright.onclick = function(){
				arrow_move(oTd_leftSelectBlock,oTd_rightSelectBlock,true);
			}
			
			oArrow_right.onclick = function(){
				arrow_move(oTd_leftSelectBlock,oTd_rightSelectBlock,false);
			}
			
			oArrow_allleft.onclick = function(){
				arrow_move(oTd_rightSelectBlock,oTd_leftSelectBlock,true);
			}
			
			oArrow_left.onclick = function(){
				arrow_move(oTd_rightSelectBlock,oTd_leftSelectBlock,false);
			}
			obj.appendChild(oArrow_allright);
			obj.appendChild(oArrow_right);
			obj.appendChild(oArrow_left);
			obj.appendChild(oArrow_allleft);
		}
		
		function arrow_move(obj1,obj2,isAll){
			for(var i = 0; i < obj1.getElementsByTagName('ul').length; i++){
				if(obj1.getElementsByTagName('ul')[i].style.display == ""){
					if(CommonFunctions._isIE6) obj1.getElementsByTagName('ul')[i].parentNode.style.overflow = "auto";
					l_i = i;
					break;
				}
			}
			for(var i = 0; i < obj2.getElementsByTagName('ul').length; i++){
				if(obj2.getElementsByTagName('ul')[i].style.display == ""){
					if(CommonFunctions._isIE6) obj2.getElementsByTagName('ul')[0].parentNode.style.overflow = "auto";
					r_i = i;
					break;
				}
			}
			for(var i = 0; i < obj1.getElementsByTagName('ul')[l_i].getElementsByTagName('li').length; i++){
				if(obj1.getElementsByTagName('ul')[l_i].getElementsByTagName('li')[i].style.display != "none"){
					if(isAll == true){
						move_do(obj1,l_i,obj2,r_i,i);
						i--;
					}else{
						if(obj1.getElementsByTagName('ul')[l_i].getElementsByTagName('li')[i].getElementsByTagName('a')[0].className == styles.active){
							move_do(obj1,l_i,obj2,r_i,i);
							i--;
						}
					}
				}
			}
			if(CommonFunctions._isIE6){
				if(obj1.getElementsByTagName('ul')[l_i].getElementsByTagName('li').length == 0){
					obj1.getElementsByTagName('ul')[l_i].parentNode.style.overflow = "visible";
				}
			}
		}
		function move_do(obj1,obj1_i,obj2,obj2_i,i){
			var oLi = document.createElement('li');
			var oA = document.createElement('a');
			oA.innerHTML = obj1.getElementsByTagName('ul')[obj1_i].getElementsByTagName('li')[i].getElementsByTagName('a')[0].innerHTML;
			oA.title = obj1.getElementsByTagName('ul')[obj1_i].getElementsByTagName('li')[i].getElementsByTagName('a')[0].title;
			oA.id = obj1.getElementsByTagName('ul')[obj1_i].getElementsByTagName('li')[i].getElementsByTagName('a')[0].id;
			oA.className = styles.normal;
			oA.onclick = obj1.getElementsByTagName('ul')[obj1_i].getElementsByTagName('li')[i].getElementsByTagName('a')[0].onclick;
			oLi.appendChild(oA);
			obj1.getElementsByTagName('ul')[obj1_i].removeChild(obj1.getElementsByTagName('ul')[obj1_i].getElementsByTagName('li')[i]);
			obj2.getElementsByTagName('ul')[obj2_i].appendChild(oLi);
		}
	}catch(e){}
}